// pages/user_center/user_info/common_editer/common_editer.js
Page({
  data:{
    formError:false,
    errorMessage:'表单错误'
  },
  onLoad:function(options){
    // 页面初始化 options为页面跳转所带来的参数
    console.log('log',options.cName);
    console.log('log',options.title);
    this.setData({
      cName: options.cName,
      title: options.title
    });
  },
  onReady:function(){
    // 页面渲染完成
  },
  onShow:function(){
    // 页面显示
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  },

  submit:function(e){
    var object = e.detail.value;

    var cNameL = object.cNameL;
    var Tel = wx.getStorageSync('username');
    if(!Tel) return;

    var that = this;

    wx.request({
      url: 'https://www.lanshuicar.com/Server/CustS/CustInfo.ashx',
      data: {
        Tel: Tel,
        Name: cNameL
      },
      method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      // header: {}, // 设置请求的 header
      success: function(res){
        // success
        console.log('log',res.data);
        var code = res.data.code;
        if(code == 0){
          wx.showToast({
            title: '修改成功',
            icon: 'success',
            duration: 2000
          });

          setTimeout(function(){
            wx.navigateBack();
          },1000)
          
        }else{
          that.setData({
            formError:true,
            errorMessage:res.data.msg
          });

          setTimeout(function(){
              that.setData({
                  formError: false,
                  errorMessage:'表单错误'
              });
          }, 3000);
        }
        
      },
      fail: function() {
        // fail
        that.setData({
          formError:true,
          errorMessage:'表单错误'
        });

        setTimeout(function(){
            that.setData({
                formError: false,
                errorMessage:'表单错误'
            });
        }, 3000);
      },
      complete: function() {
        // complete
      }
    })
  }
})